# 密码是3个小写字母
with open("./p059_cipher.txt", "r") as f:
    input_str = f.read()

plaintext1 = ''
plaintext2 = ''
plaintext3 = ''
ciphertext = input_str.split(',')
for i in range(0, len(ciphertext), 3):
    plaintext1 += chr(int(ciphertext[i]))
    plaintext2 += chr(int(ciphertext[i + 1]))
    plaintext3 += chr(int(ciphertext[i + 2]))
print(plaintext1)
print("=================")
print(plaintext2)
print("=================")
print(plaintext3)
# 从上面的输出猜测是exp，因为同一个位置上是相同的密钥，而与空格异或之后所得到的是大小写之间的转换
key = 'exp'
plaintext = ''
res = 0
for i in range(0, len(ciphertext), 3):
    p1 = int(ciphertext[i]) ^ ord(key[0])
    p2 = int(ciphertext[i + 1]) ^ ord(key[1])
    p3 = int(ciphertext[i + 2]) ^ ord(key[2])
    res += (p1 + p2 + p3)
    plaintext += chr(p1)
    plaintext += chr(p2)
    plaintext += chr(p3)
print(plaintext)
print(res)
